<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\api\service\OrderItemService;
use app\api\service\OrderService;
use app\api\service\PayService;
use app\api\service\UserDressupPackagedService;
use app\common\controller\Api;
use app\common\controller\ApiBase;
use think\Log;
use Yansongda\Pay\Pay;

class Topay extends ApiBase
{

    protected $noNeedLogin = ['notify'];
    protected $noNeedRight = ['index'];


    public function index()
    {
        $this->checkRequestParam(\app\common\validate\Topay::class);
        $param = $this->request->param();
        $user = $this->auth->getUserinfo();
        $service = new PayService();
        $result = $service->ToPay($param, $this->auth->id, $user->thrid->openid ?? "");
        if (empty($result)) {
            $this->error($service->getMsg());
        }
        $this->success('成功', ['params' => $result]);
    }

    public function notify()
    {
        $type = $this->request->param('type');
        $param = $this->request->param();
        $data = $type == 'wechat' ? file_get_contents('php://input') : request()->post();
        //        Log::write($data, 'pay_notify');
        $service = new PayService();
        $result = $service->notify($param);
    }
}
